/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header: https://192.168.1.224/svn/elancom/product/elancom-platform/trunk/src/main/java/com/elancom/framework/commons/json/serializer/FilterUtils.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Id: FilterUtils.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Author: lanzhouxue $
 * $Date: 2012-07-02 11:09:12 +0800 (Mon, 02 Jul 2012) $
 * $Revision: 1034 $
 */
package com.elancom.framework.commons.json.serializer;

import java.util.List;

public class FilterUtils {
	public static Object processValue(JSONSerializer serializer, Object object, String key, Object propertyValue) {
		final List<ValueFilter> valueFilters = serializer.getValueFiltersDirect();
		if (valueFilters != null) {
			for (final ValueFilter valueFilter : valueFilters) {
				propertyValue = valueFilter.process(object, key, propertyValue);
			}
		}

		return propertyValue;
	}

	public static String processKey(JSONSerializer serializer, Object object, String key, Object propertyValue) {
		final List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
		if (nameFilters != null) {
			for (final NameFilter nameFilter : nameFilters) {
				key = nameFilter.process(object, key, propertyValue);
			}
		}

		return key;
	}

	public static String processKey(JSONSerializer serializer, Object object, String key, byte intValue) {
		final List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
		if (nameFilters != null) {
			final Object propertyValue = Byte.valueOf(intValue);

			for (final NameFilter nameFilter : nameFilters) {
				key = nameFilter.process(object, key, propertyValue);
			}
		}

		return key;
	}

	public static String processKey(JSONSerializer serializer, Object object, String key, short intValue) {
		final List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
		if (nameFilters != null) {
			final Object propertyValue = Short.valueOf(intValue);

			for (final NameFilter nameFilter : nameFilters) {
				key = nameFilter.process(object, key, propertyValue);
			}
		}

		return key;
	}

	public static String processKey(JSONSerializer serializer, Object object, String key, int intValue) {
		final List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
		if (nameFilters != null) {
			final Object propertyValue = Integer.valueOf(intValue);

			for (final NameFilter nameFilter : nameFilters) {
				key = nameFilter.process(object, key, propertyValue);
			}
		}

		return key;
	}

	public static String processKey(JSONSerializer serializer, Object object, String key, long intValue) {
		final List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
		if (nameFilters != null) {
			final Object propertyValue = Long.valueOf(intValue);

			for (final NameFilter nameFilter : nameFilters) {
				key = nameFilter.process(object, key, propertyValue);
			}
		}

		return key;
	}

	public static String processKey(JSONSerializer serializer, Object object, String key, float intValue) {
		final List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
		if (nameFilters != null) {
			final Object propertyValue = Float.valueOf(intValue);

			for (final NameFilter nameFilter : nameFilters) {
				key = nameFilter.process(object, key, propertyValue);
			}
		}

		return key;
	}

	public static String processKey(JSONSerializer serializer, Object object, String key, double intValue) {
		final List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
		if (nameFilters != null) {
			final Object propertyValue = Double.valueOf(intValue);

			for (final NameFilter nameFilter : nameFilters) {
				key = nameFilter.process(object, key, propertyValue);
			}
		}

		return key;
	}

	public static String processKey(JSONSerializer serializer, Object object, String key, boolean intValue) {
		final List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
		if (nameFilters != null) {
			final Object propertyValue = Boolean.valueOf(intValue);

			for (final NameFilter nameFilter : nameFilters) {
				key = nameFilter.process(object, key, propertyValue);
			}
		}

		return key;
	}

	public static String processKey(JSONSerializer serializer, Object object, String key, char intValue) {
		final List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
		if (nameFilters != null) {
			final Object propertyValue = Character.valueOf(intValue);

			for (final NameFilter nameFilter : nameFilters) {
				key = nameFilter.process(object, key, propertyValue);
			}
		}

		return key;
	}

	public static boolean apply(JSONSerializer serializer, Object object, String key, Object propertyValue) {
		final List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();

		if (propertyFilters != null) {
			final boolean apply = true;
			for (final PropertyFilter propertyFilter : propertyFilters) {
				if (!propertyFilter.apply(object, key, propertyValue)) {
					return false;
				}
			}

			return apply;
		}

		return true;
	}

	public static boolean apply(JSONSerializer serializer, Object object, String key, byte value) {
		final List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();

		if (propertyFilters != null) {
			final boolean apply = true;

			final Object propertyValue = Byte.valueOf(value);
			for (final PropertyFilter propertyFilter : propertyFilters) {
				if (!propertyFilter.apply(object, key, propertyValue)) {
					return false;
				}
			}

			return apply;
		}

		return true;
	}

	public static boolean apply(JSONSerializer serializer, Object object, String key, short value) {
		final List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();

		if (propertyFilters != null) {
			final boolean apply = true;

			final Object propertyValue = Short.valueOf(value);
			for (final PropertyFilter propertyFilter : propertyFilters) {
				if (!propertyFilter.apply(object, key, propertyValue)) {
					return false;
				}
			}

			return apply;
		}

		return true;
	}

	public static boolean apply(JSONSerializer serializer, Object object, String key, int value) {
		final List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();

		if (propertyFilters != null) {
			final boolean apply = true;

			final Object propertyValue = Integer.valueOf(value);
			for (final PropertyFilter propertyFilter : propertyFilters) {
				if (!propertyFilter.apply(object, key, propertyValue)) {
					return false;
				}
			}

			return apply;
		}

		return true;
	}

	public static boolean apply(JSONSerializer serializer, Object object, String key, char value) {
		final List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();

		if (propertyFilters != null) {
			final boolean apply = true;

			final Object propertyValue = Character.valueOf(value);
			for (final PropertyFilter propertyFilter : propertyFilters) {
				if (!propertyFilter.apply(object, key, propertyValue)) {
					return false;
				}
			}

			return apply;
		}

		return true;
	}

	public static boolean apply(JSONSerializer serializer, Object object, String key, long value) {
		final List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();

		if (propertyFilters != null) {
			final boolean apply = true;

			final Object propertyValue = Long.valueOf(value);
			for (final PropertyFilter propertyFilter : propertyFilters) {
				if (!propertyFilter.apply(object, key, propertyValue)) {
					return false;
				}
			}

			return apply;
		}

		return true;
	}

	public static boolean apply(JSONSerializer serializer, Object object, String key, float value) {
		final List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();

		if (propertyFilters != null) {
			final boolean apply = true;

			final Object propertyValue = Float.valueOf(value);
			for (final PropertyFilter propertyFilter : propertyFilters) {
				if (!propertyFilter.apply(object, key, propertyValue)) {
					return false;
				}
			}

			return apply;
		}

		return true;
	}

	public static boolean apply(JSONSerializer serializer, Object object, String key, double value) {
		final List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();

		if (propertyFilters != null) {
			final boolean apply = true;

			final Object propertyValue = Double.valueOf(value);
			for (final PropertyFilter propertyFilter : propertyFilters) {
				if (!propertyFilter.apply(object, key, propertyValue)) {
					return false;
				}
			}

			return apply;
		}

		return true;
	}
}
